package com.vint.leetcode;

import com.vint.common.TreeNode;

/**
 * 树值之和
 */
public class Leetcode129 {
	public int sum = 0;
    public int sumNumbers(TreeNode root) {
    	sumLeaf(root, 0);
    	return sum;
    }

    public void sumLeaf(TreeNode root, int val) {
    	if(root==null)return;
	    if(null==root.right&&null==root.left) {
	    	sum += root.val + val * 10;
	    }
	    sumLeaf(root.left, val * 10 + root.val);
	    sumLeaf(root.right, val * 10 + root.val);
    }
}
